| Conditions | 2 |
| Total Lines | 23 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import { CommandHandler } from '@nestjs/cqrs'; |
||
| 19 | |||
| 20 | public async execute(command: CreateUserCommand): Promise<string> { |
||
| 21 | const { firstName, lastName, password, role } = command; |
||
| 22 | const email = command.email.toLowerCase(); |
||
| 23 | |||
| 24 | if (true === (await this.isEmailAlreadyExist.isSatisfiedBy(email))) { |
||
| 25 | throw new EmailAlreadyExistException(); |
||
| 26 | } |
||
| 27 | |||
| 28 | const hashPassword = await this.passwordEncoder.hash(password); |
||
| 29 | const apiToken = await this.passwordEncoder.hash(email + password); |
||
| 30 | const user = await this.userRepository.save( |
||
| 31 | new User( |
||
| 32 | firstName, |
||
| 33 | lastName, |
||
| 34 | email, |
||
| 35 | apiToken, |
||
| 36 | hashPassword, |
||
| 37 | role |
||
| 38 | ) |
||
| 39 | ); |
||
| 40 | |||
| 41 | return user.getId(); |
||
| 42 | } |
||
| 44 |